<?php
session_start();

require_once("conf/configuration.inc");
$section = isset($_GET["section"]) ? $_GET["section"] : DEFAULT_SECTION;

require_once(LIBRARIES_DIR."Utils.php");
require_once(LIBRARIES_DIR."DBManager.php");
require_once(LIBRARIES_DIR."ContentManager.php");

// Establecemos el idioma
$lang = Utils::setLanguage();

if ($section != "login" && !isset($_SESSION["adminLoggedUserName"])) {
	$url = Utils::generateSEOUrl($lang, "login");
	header("location: ".$url);
	exit;
}

// Conectamos con la bd
$db = new DBManager();
$db->connect();

// Comprobamos si la página tiene que ir con ssl o no
if (CHECK_PROTOCOL == 1) {
	Utils::checkProtocol($section);
}

$content = new ContentManager($lang);
$content->initiate($section);

$includeName = $section;
if (!empty($_GET["subsection"])) {
	$includeName .= "-".$_GET["subsection"];
}
include(INCLUDES_DIR.$includeName.".php");
$tplFile = TEMPLATES_DIR.$includeName.".tpl";
if (file_exists($tplFile)) {
	$content->display($tplFile);
}
?>
